From 5ef53bb049f61a4524aff56a8d5fc2b3ccd1b65d Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 28 Oct 2005 01:08:49 +0000 Subject: [PATCH] Give informative connection errors more often --- includes/Database.php | 25 ++++++++++++++++++++----- includes/LoadBalancer.php | 5 +++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 5aef1bb2f3..3d2f5c0daa 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -221,6 +221,8 @@ class Database { * If the failFunction is set to a non-zero integer, returns success */ function open( $server, $user, $password, $dbName ) { + global $wguname; + # Test for missing mysql.so # First try to load it if (!@extension_loaded('mysql')) { @@ -258,7 +260,9 @@ class Database { if ( $this->mConn !== false ) { $success = @/**/mysql_select_db( $dbName, $this->mConn ); if ( !$success ) { - wfDebug( "Error selecting database \"$dbName\": " . $this->lastError() . "\n" ); + $error = "Error selecting database $dbname on server {$this->mServer} " . + "from client host {$wguname['nodename']}\n"; + wfDebug( $error ); } } else { wfDebug( "DB connection error\n" ); @@ -308,16 +312,21 @@ class Database { /** * @access private - * @param string $msg error message ? + * @param string $error fallback error message, used if none is given by MySQL */ - function reportConnectionError() { + function reportConnectionError( $error = 'Unknown error' ) { + $myError = $this->lastError(); + if ( $myError ) { + $error = $myError; + } + if ( $this->mFailFunction ) { if ( !is_int( $this->mFailFunction ) ) { $ff = $this->mFailFunction; - $ff( $this, $this->lastError() ); + $ff( $this, $error ); } } else { - wfEmergencyAbort( $this, $this->lastError() ); + wfEmergencyAbort( $this, $error ); } } @@ -1764,6 +1773,12 @@ border=\"0\" ALT=\"Google\"> if ( is_object( $wgMessageCache ) ) { $wgMessageCache->disable(); } + + if ( trim( $error ) == '' ) { + $error = $this->mServer; + } + + wfLogDBError( "Connection error: $error\n" ); $msg = wfGetSiteNotice(); if($msg == '') { diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index 89860d792f..aaa4d839da 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -226,6 +226,7 @@ class LoadBalancer { } while ( count( $loads ) && !$done && $totalElapsed / 1e6 < $wgDBClusterTimeout ); if ( $totalElapsed / 1e6 >= $wgDBClusterTimeout ) { + $this->mErrorConnection = false; $this->mLastError = 'All servers busy'; } @@ -454,7 +455,7 @@ class LoadBalancer { $conn = new Database; if ( $this->mFailFunction ) { $conn->failFunction( $this->mFailFunction ); - $conn->reportConnectionError(); + $conn->reportConnectionError( $this->mLastError ); } else { // If all servers were busy, mLastError will contain something sensible wfEmergencyAbort( $conn, $this->mLastError ); @@ -465,7 +466,7 @@ class LoadBalancer { } else { $conn->failFunction( false ); } - $conn->reportConnectionError(); + $conn->reportConnectionError( "{$this->mLastError} ({$conn->mServer})" ); } $reporting = false; } -- 2.20.1